package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.saas.domain.dao.DingBundleLogDao;
import com.xbongbong.saas.domain.dao.DingBundleUserDao;
import com.xbongbong.saas.domain.entity.DingBundleLogEntity;
import com.xbongbong.saas.domain.entity.DingBundleUserEntity;
import com.xbongbong.saas.model.DingBundleLogModel;
import com.xbongbong.saas.model.DingBundleUserModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author chenshan
 * @version v1.0
 * @since 2019-08-16 10:50
 */
@Service("dingBundleLogModel")
public class DingBundleLogModelImpl implements DingBundleLogModel {
    
    @Resource
    private DingBundleLogDao dingBundleLogDao;
    
    @Override
    public Integer insert(DingBundleLogEntity entity) {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        return dingBundleLogDao.insert(entity);
    }
    
    @Override
    public Integer insert(String corpid, String userId, String platform) {
        DingBundleLogEntity entity = new DingBundleLogEntity();
        entity.setCorpid(corpid);
        entity.setUserId(userId);
        entity.setPlatform(platform);
        return dingBundleLogDao.insert(entity);
    }
    
    @Override
    public void insertBatch(List<DingBundleLogEntity> dingBundleLogList) {
        dingBundleLogDao.insertBatch(dingBundleLogList);
    }
    
    @Override
    public Integer save(DingBundleLogEntity entity) {
        if ( entity.getId() == null || entity.getId().equals(0L) ) {
            return insert(entity);
        }
        return update(entity);
    }
    
    @Override
    public Integer update(DingBundleLogEntity entity) {
        return dingBundleLogDao.update(entity);
    }
    
    @Override
    public DingBundleUserEntity getEntity(Long id, String corpid) {
        return dingBundleLogDao.getByKey(id, corpid);
    }
    
    @Override
    public Integer deleteByIds(List<Long> ids, String corpid) {
        return dingBundleLogDao.deleteByIdIn(ids,corpid);
    }
    
    @Override
    public List findEntitys(Map<String, Object> param) {
        return dingBundleLogDao.findEntitys(param);
    }
    
    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dingBundleLogDao.getEntitysCount(param);
    }
    
    /**
     * Description: 查询符合条件的数据（无子表单数据）
     *
     * @param param
     * @return java.util.List<T>
     * @throws
     * @author 魏荣杰
     * @date 2020/10/13 16:07
     * @since
     */
    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }
    
    @Override
    public DingBundleLogEntity getEntityByUserId(String userId, String corpid) {
        return dingBundleLogDao.getEntityByUserId(userId,corpid);
    }
}